package org.example.springboot;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

public class JSONTest {
    public static void main(String[] args) throws JsonProcessingException {
        ObjectMapper objectMapper = new ObjectMapper();

        Param param = new Param();
        param.setName("张三");
        param.setAge(10);
        param.setOther("学生");

        // 对象转成JSON
        String s = objectMapper.writeValueAsString(param);
        System.out.println(s);

        // JSON转成对象
        Param param1 = objectMapper.readValue(s,Param.class);
        System.out.println(param1.toString());
    }
}
